<?php
if (array_key_exists("check", $_GET)){
	switch ($_GET['check']){
		case "latency":
			die();
		case "headers":
			$p_headers=apache_request_headers();
			$data = "{";
			foreach ($p_headers as $key => $value){
				$data .= "'" . $key . "': '" . $value . "', ";
			}
			$data .= "}";
			print encode($data);
	}
}

function encode($data){
	$result  = "\n=== START CHOPITO DATA ===\n";
	$result .= urlsafe_b64encode($data);
	$result .= "\n=== END CHOPITO DATA ===\n";
	return $result;
}

function urlsafe_b64encode($string) {
    $data = base64_encode($string);
    $data = str_replace(array('+','/'),array('-','_'),$data);
    return $data;
}

?>
